#include <bits/stdc++.h>
using namespace std;

const int maxn = 110;
string s[maxn];
int main() {
	int m, n;
	cin >> m;
	for (int i=1; i<=m; i++) {
		cin >> n;
		string ss;
		for (int j=1; j<=n; j++) {
			cin >> s[j];
			ss += s[j];
		}
		sort(ss.begin(), ss.end());
		sort(s+1, s+n+1);
		string sk;
		for (int j=1; j<=n; j++) {
			sk += s[j];
		}
		if (ss == sk) {
			cout << 1 << endl;
		} else {
			cout << 0 << endl;
		}
	}
	return 0;
}
